package com.cyc.callable;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class MyTest{
    public static void main(String[] args) throws ExecutionException, InterruptedException {

        CallTest callTest = new CallTest();
        FutureTask futureTask = new FutureTask(callTest);
        new Thread(futureTask,"A").start();
        new Thread(futureTask,"B").start();//结果会被缓存，效率高
        String res = (String) futureTask.get();//获取返回结果  可能会产生阻塞 一般放到最后，
        // 或者通过异步
        System.out.println(res);
    }
}

class CallTest implements Callable<String> {
    @Override
    public String call() throws Exception {
        System.out.println("call()->");
        return "cyc";
    }
}
